<html>
<head><meta charset="utf-8"><title>Closure `Ty` into `impl FnOnce`-type syntax as... · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html">Closure `Ty` into `impl FnOnce`-type syntax as...</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220635045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as.../near/220635045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html#220635045">(Dec 21 2020 at 21:53)</a>:</h4>
<p><span class="user-mention" data-user-id="326843">@James</span> You might want to rename your Zulip topic to <code>get closure return type</code> or something so that it's clearer to people what you're looking for.</p>



<a name="220652864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as.../near/220652864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html#220652864">(Dec 22 2020 at 02:24)</a>:</h4>
<p>This was resolved by using a different type of suggestion by suggesting to just use <code>Fn</code> trait bounds with further reading (in the rust by example book) as I feel that trying to hack up some type of pretty-printer for <code>Fn()</code> syntax sugar was out-of-scope for my abilities—perhaps someone in a future PR could update that to make it better.<br>
e.g.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">_</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>would output</p>
<div class="codehilite"><pre><span></span><code>error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --&gt; &lt;anon&gt;:1:11
  |
1 | fn f() -&gt; _ { || 0 }
  |           ^ not allowed in type signatures
  |
  = help: consider using an `Fn`, `FnMut`, or `FnOnce` trait bound
  = note: For more information on using `Fn` traits with function outputs, see https://doc.rust-lang.org/rust-by-example/fn/closures/output_parameters.html

error: aborting due to previous error

For more information about this error, try `rustc --explain E0121`.
</code></pre></div>



<a name="220652901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as.../near/220652901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html#220652901">(Dec 22 2020 at 02:26)</a>:</h4>
<p>before it would just suggest</p>
<div class="codehilite"><pre><span></span><code>error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --&gt; &lt;anon&gt;:1:11
  |
1 | fn f() -&gt; _ { || 0 }
  |           ^
  |           |
  |           not allowed in type signatures
  |           help: replace with the correct return type: `[closure@&lt;anon&gt;:1:15: 1:19]`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0121`.
</code></pre></div>
<p>which is definitely a papercut because unique closure types are not valid syntax; you must use generics with <code>Fn()</code> trait bounds or <code>impl Fn()</code> syntax</p>



<a name="220653143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as.../near/220653143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html#220653143">(Dec 22 2020 at 02:31)</a>:</h4>
<p>By the way, the note should be lowercase:</p>
<div class="codehilite"><pre><span></span><code>  = note: for more information on using `Fn` traits with function outputs, see https://doc.rust-lang.org/rust-by-example/fn/closures/output_parameters.html
</code></pre></div>
<p>What does "<code>Fn</code> traits with function outputs" mean? I think you should just say "for more information on the types of closures" or something.</p>
<p>And it probably is a good idea to link to the Book instead of Rust by Example, which is not usually linked to in rustc output.</p>



<a name="220653153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as.../near/220653153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html#220653153">(Dec 22 2020 at 02:31)</a>:</h4>
<p>Alright</p>



<a name="220653242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as.../near/220653242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html#220653242">(Dec 22 2020 at 02:33)</a>:</h4>
<p>How does</p>
<div class="codehilite"><pre><span></span><code>for more information on `Fn` traits and the types of closures, see https://doc.rust-lang.org/book/ch13-01-closures.html
</code></pre></div>
<p>sound?</p>



<a name="220653372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as.../near/220653372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html#220653372">(Dec 22 2020 at 02:35)</a>:</h4>
<p>Sounds good! I realize I'm the one who suggested "the types of closures" but "closure types" might be clearer. Thanks for contributing :)</p>



<a name="220653381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Closure%20%60Ty%60%20into%20%60impl%20FnOnce%60-type%20syntax%20as.../near/220653381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Closure.20.60Ty.60.20into.20.60impl.20FnOnce.60-type.20syntax.20as.2E.2E.2E.html#220653381">(Dec 22 2020 at 02:35)</a>:</h4>
<p>Alright.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>